import util from '../../../utils/util.js'
import api from '../../../config/api.js'

const app = getApp();
Page({
  data: {
    trip: {},
    options: null
  },
  onReady() {
    const self = this;
    wx.setNavigationBarTitle({
      title: self.data.options.name,
    });
  },
  onLoad(options) {
    const self = this;
    const id = options.id;
    self.setData({
      options
    });
    wx.showToast({
      title: '正在加载',
      icon: 'loading',
      duration: 12000
    });
    util.request(api.tripInfoByID + id + '/waypoints/').then(function (res) {
      const trip = res;
      self.setData({
        trip,  
      }, function () {
        wx.hideToast();
      });
    });
  },
  viewWaypoint(e) {
    const self = this;
    const ds = e.currentTarget.dataset;
    wx.navigateTo({
      url: `../waypoint/waypoint?waypointId=${ds.waypoint}&tripId=${self.data.trip.id}`,
    });
  },
  gotoUser(e) {
    const userId = e.target.dataset.id;
    wx.navigateTo({
      url: `../user/user?id=${userId}`,
    });
  },
});
